<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="会员ID" prop="sysUserid">
        <el-input
          v-model="queryParams.sysUserid"
          placeholder="请输入会员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入会员手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="团队等级" prop="memberName">
        <el-select
          v-model="queryParams.memberName"
          placeholder="请选择团队等级"
          clearable
          @change="teamLevelChange"
        >
          <el-option
            v-for="item in levelList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="createStartTime">
        <el-date-picker
          v-model="queryParams.createStartTime"
          type="date"
          placeholder="请选择开始时间"
          clearable
          :editable="false"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="createEndTime">
        <el-date-picker
          v-model="queryParams.createEndTime"
          type="date"
          placeholder="请选择结束时间"
          clearable
          :editable="false"
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table :data="pageList" highlight-current-row>
      <el-table-column label="会员ID" align="center" prop="userId" width="80" />
      <el-table-column
        label="用户信息"
        align="center"
        prop="nickName"
        width="180"
      >
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.avatar"
            ></el-image>
            <div>
              <div>{{ scope.row.nickName }}</div>
              <div>{{ scope.row.phoneNumber }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="团队等级" align="center" prop="teamLevel">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.teamLevel == 1">VIP</el-tag>
          <el-tag v-if="scope.row.teamLevel == 2">SVIP</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column
        label="升级时间"
        align="center"
        prop="updateTime"
        width="160"
      />
      <el-table-column
        label="助力升级会员"
        align="center"
        prop="memberUpgradeNumber"
        width="100"
      >
        <template slot-scope="scope">
          <div>共{{ scope.row.memberUpgradeNumber }}人</div>

          <el-button
            type="text"
            size="mini"
            @click="exchange(scope.row)"
            v-if="scope.row.memberUpgradeNumber > 0"
            >查看</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        label="推荐人"
        align="center"
        prop="referrerName"
        width="180"
      >
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.referrerAvatar"
            ></el-image>
            <div>
              <div>ID：{{ scope.row.referrerUserId }}</div>
              <div>{{ scope.row.referrerNickName }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="平台补贴用户"
        align="center"
        prop="subsidyUser"
        width="200"
      >
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.subsidyAvatar"
            ></el-image>
            <div>
              <div>ID：{{ scope.row.subsidyUserId }}</div>
              <div>{{ scope.row.subsidyNickName }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="奖励类型"
        align="center"
        prop="commissionTypeName"
      />
      <el-table-column
        label="已结算佣金"
        align="center"
        prop="memberCloseMoney"
        width="100"
      />
      <!-- <el-table-column label="冻结基金" align="center" prop="frozenFund" /> -->
      <el-table-column label="业绩" align="center" prop="performance" />
      <el-table-column label="市场业绩" align="center" prop="onePerformance">
        <template slot-scope="scope">
          <el-tooltip
            effect="light"
            content="暂无市场"
            placement="top"
            v-if="
              scope.row.onePerformance == 0 && scope.row.twoPerformance == 0
            "
          >
            <el-button plain size="mini">查看</el-button>
          </el-tooltip>
          <el-tooltip effect="light" placement="top" v-else>
            <template slot="content">
              <div>第一市场：¥{{ scope.row.onePerformance }}</div>
              <div>第二市场：¥{{ scope.row.twoPerformance }}</div>
            </template>
            <el-button plain size="mini">查看</el-button>
          </el-tooltip>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="解冻基金达标"
        align="center"
        prop="unfrozenFunds"
        width="100"
      >
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.unfrozenFunds == 0"
            >未达标</el-tag
          >
          <el-tag type="danger" v-else-if="scope.row.unfrozenFunds == 1"
            >已达标</el-tag
          >
          <span v-else>-</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="加入时间"
        align="center"
        prop="createTime"
        width="180"
      />
      <!-- <el-table-column
        label="启用最高奖励"
        align="center"
        prop="enableMaximumRewards"
        width="100"
      >
        <template slot-scope="scope">
          <el-switch v-model="scope.row.enableMaximumRewards"></el-switch>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="最高奖励" align="center" prop="maximumRewards" /> -->
      <!-- <el-table-column label="操作" align="center" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="setMaximumRewards"
            >设置最高奖励</el-button
          >
        </template>
      </el-table-column> -->

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        :width="70"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="getList1(scope.row.userId)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- total -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <TeamManageDialog ref="teamManageDialogRef"></TeamManageDialog>

    <el-dialog
      title="助力用户"
      :visible.sync="open1"
      width="700px"
      append-to-body
    >
      <div class="dialog-table">
        <el-table :data="tableData" row-key="userId" ref="table">
          <!-- <el-table-column prop="parentId" label="父id"></el-table-column> -->
          <el-table-column prop="userId" label="用户Id"></el-table-column>
          <el-table-column
            prop="beforeLocation"
            label="变动前位置"
          ></el-table-column>
          <el-table-column
            prop="afterLocation"
            label="变动后位置"
          ></el-table-column>
          <el-table-column prop="createTime" label="创建时间"></el-table-column>
          <el-table-column prop="createBy" label="创建人"></el-table-column>
        </el-table>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="open1 = false">确 定</el-button>
        <el-button @click="open1 = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { teamManageList, listLog } from "@/api/doubleCopy/teamManage";
import TeamManageDialog from "./components/teamManageDialog.vue";
export default {
  name: "TeamManage",
  components: { TeamManageDialog },
  data() {
    return {
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysUserid: null,
        phone: null,
        // teamLevel: null,
        createStartTime: null,
        createEndTime: null,
      },
      // 团队级别
      levelList: [
        {
          value: 1,
          name: "VIP",
        },
        {
          value: 2,
          name: "SVIP",
        },
        {
          value: 3,
          name: "共享店主",
        },
        {
          value: 4,
          name: "联创",
        },
        {
          value: 5,
          name: "区域运营",
        },
        {
          value: 6,
          name: "总裁",
        },
      ],
      // 表格数据
      pageList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      tableData: [],
    };
  },
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    // 查询团队列表
    getList() {
      this.loading = true;
      teamManageList(this.queryParams).then((response) => {
        this.pageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getList1(id) {
      this.loading = true;
      listLog({
        pageNum: 1,
        pageSize: 999999,
        parentId: id,
      }).then((response) => {
        this.open1 = true;

        this.tableData = response.rows;
      });
    },
    teamLevelChange(val) {
      console.log("val-----", val);
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 表单重置
    reset() {
      // this.form = {
      //   maximumRewards: null,
      // };
      this.resetForm("form");
    },
    // 设置最高奖励
    setMaximumRewards() {
      this.reset();
      this.open = true;
      this.title = "设置佣金最高奖励";
    },

    exchange(row) {
      this.title = "助力用户";
      this.$refs.teamManageDialogRef.show(row);
    },
    // 提交按钮
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
  },
};
</script>

<style lang="less" scoped>
.user-box {
  display: flex;
  justify-content: center;
}
</style>
